//玩家相关的循环逻辑


//每隔60s删除玩家组的AI单位
[] spawn
{
	while {true} do
	{
		sleep 120;
		{
			{	
				if(!isPlayer _x) then
				{
					deleteVehicle _x;
				};
			}forEach (units group _x);
		}forEach (call fn_getPlayerRed);
		
	};
	
};

//远离的倒地玩家直接死亡
[] spawn
{
	if(Param_FarDeath == 0) exitWith{};
	while {true} do
	{
		waitUntil{Sleep 10;(count call fn_getPlayerRed) > 3};
		{
			if(_x getVariable ['FAR_isUnconscious',0] == 1) then
			{
				private _player_1 = [_x, Param_FarDeath] call fn_getPlayerNear;
				if(isNull _player_1) then
				{
					_x setDamage 1;
				};
			};
		}forEach (call fn_getPlayerRed);
		
		
	};
};

//远离的倒地玩家 被AI嘲讽 = =
[] spawn
{
	while {true} do
	{
		sleep 60;
		{
			if(alive _x
			&& {_x getVariable ['FAR_isUnconscious',0] == 1}) then
			{
				if(!(_x getVariable ["as_pee_ed", false]))then{
					private _player_1 = [_x, 400] call fn_getPlayerNear;
					if(isNull _player_1) then
					{
						private _list = [];
						_list = _x nearEntities ["Man", 50];
						_list = _list select {!isPlayer _x && alive _x && {side _x == west || side _x == resistance} };
						if(count _list != 0)then{
							[selectRandom _list, _x] spawn{
								params["_unit", "_player"];
								//_unit doWatch _player;
								while{alive _unit} do{
									_unit doMove (position _player);
									waitUntil{sleep 1;unitReady _unit};
									if(!alive _player) exitWith{};
									if(_unit distance2D _player < 2)exitWith{
										doStop _unit;
										_unit setDir (_unit getDir _player);
										[_unit, selectRandom ast_taunt] remoteExec ["say3D", 0];
										_unit remoteExec["fn_pee", 0];
										_player setVariable ["as_pee_ed", true];
										//_player remoteExec ["fn_camToUnit", 0];
										
										//
										[east, name _player, "STR_TAG_O_13_1"] remoteExec ["fn_talk", 0];
										as_onkeydo_camToUnit = _player;
										publicVariable "as_onkeydo_camToUnit";
										[]spawn{
											Sleep 10;
											as_onkeydo_camToUnit = objNull;
											publicVariable "as_onkeydo_camToUnit";
										};
										
										//
										//_unit doWatch objNull;
									};
								};
							};	
						};
					};
				};
			}else
			{
				_x setVariable ["as_pee_ed", false];
			};
		}forEach (call fn_getPlayerRed);	
	};
};

//上校呼叫支援
[] spawn
{
	waitUntil {as_map_viewed};
	waitUntil {(!isNil "as_npc")};
	
	private _player = objNull;
	waitUntil 
	{
		Sleep 60;
		_player = [as_npc, 2000] call fn_getPlayerAttack;
		!isNull _player
	};
	
	Sleep 180;
	
	if(as_npc_dead) exitWith{};

	[getPos _player, 4.0] spawn fn_aiNeedSupport;		
	[resistance, "Garvas上校", selectRandom ast_npc] remoteExec ["fn_talk", 0];
	
	"LeadTrack02_F_EPA" remoteExec ["playMusic"];
};

//绿军玩家禁止使用特定载具
[] spawn
{
	while {true} do
	{
		sleep 5;
		{
			if(vehicle _x != _x) then
			{
				if((vehicle _x) getVariable ["green_disable", false]) then
				{
					moveOut _x;
					[resistance, "军官", "公共财产，禁止挪用！"] remoteExec ["fn_talk", _x];
				};
			};
		}forEach (call fn_getPlayerGreen);
		
		
	};
};

//从支援位置选择有玩家的
[] spawn
{
	while {true} do
	{
		sleep 60;
		as_gn_target = as_gn_target select {
			private _player = [_x select 0, 1000] call fn_getPlayerNear;
			!isNull _player
		};
	};
};
	